package cn.edu.swpu.cins.u_chain.frontend.controller.project;


import cn.edu.swpu.cins.u_chain.frontend.entity.dto.ResultData;
import cn.edu.swpu.cins.u_chain.frontend.entity.dto.project.*;
import cn.edu.swpu.cins.u_chain.frontend.service.RedisService;
import cn.edu.swpu.cins.u_chain.frontend.service.project.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("UChain/user/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @Autowired
    private RedisService redisService;

    @PostMapping("addPro")
    public ResultData addProject(@RequestBody AddPro addPro,@RequestHeader("userId") int userId) throws IOException {
        int proId=projectService.addPro(addPro, userId);
        return new ResultData(true, "发布项目成功",proId);
    }

    @PostMapping("uploadPRD")
    public ResultData uploadPRD(@RequestPart("PRD") MultipartFile PRD, @RequestParam("proId") int proId) throws IOException {
        projectService.uploadPRD(PRD, proId);
        return new ResultData(true, "文件上传成功");
    }

    @GetMapping("getProsInfo/{pageNum}")
    public ResultData getProsInfo(@PathVariable("pageNum") int pageNum) {
        List<ProViewDetail> viewList = projectService.getProsInfo(pageNum);
        return new ResultData(true, "项目浏览页信息", viewList);
    }

    /**
     * 此时要同时进行两步操作 ：
     * 一个是在项目的关注人列表里加入该用户
     * 另一个是在该用户的关注项目里加入项目ID
     * @param proId
     * @param userId
     * @return
     */
    @GetMapping("followPro/{proId}")
    public ResultData followPro(@PathVariable("proId") int proId, @RequestHeader("userId") int userId) {
        redisService.followPro(proId, userId);
        return new ResultData(true, "关注成功");
    }

    @GetMapping("unFollowPro/{proId}")
    public ResultData unFollowPro(@PathVariable("proId") int proId, @RequestHeader("userId") int userId) {
        redisService.unFollowPro(proId, userId);
        return new ResultData(true, "关注成功");
    }

    @GetMapping("getMinePro/{pageNum}")
    public ResultData getProByMe(@RequestHeader("userId") int userId,@PathVariable("pageNum") int pageNum) {
        List<ProViewDetail> viewList = projectService.getProsByMe(userId,pageNum);
        return new ResultData(true, "我发布过得项目", viewList);
    }

    /**
     * 查看我所有的项目评价
     *
     * @return
     */
    @GetMapping("getAllProAssess/{pageNum}")
    public ResultData getMyProAssess(@RequestHeader("userId") int userId,@PathVariable("pageNum") int pageNum) {
        MyProAssess viewList = projectService.getMyProAssess(userId, pageNum);
        return new ResultData(true, "所有关于我项目的评价", viewList);
    }

    /**
     * 申请项目
     * 1、根据需求文档填写需求模块
     * 2、上传自己的报价表
     */
}
